package view.impl.menu.items;

import org.newdawn.slick.Graphics;
import org.newdawn.slick.Image;
import org.newdawn.slick.SlickException;

import view.impl.CharacterInfo;


public class CharSelectObject implements IMenuItem{
	
	private Image charImage;			// Image on the character.
	private Image charSelectedImage;	// Image shown when the cursor is on this character.
	private Image charChosenImage;		// Image shown when this character have been chosen by the player.
	
	private int posX, posY;
	private int size;
	
	private boolean chosen = false;
	
	public CharSelectObject(CharacterInfo ci, int posX, int posY, int size) throws SlickException {
		this(new Image(ci.getCharImage()), new Image(ci.getCharSelected()), new Image(ci.getCharChosen()), posX, posY, size);
	}
	
	public CharSelectObject(Image charImage, Image charSelectedImage, Image charChosenImage, int posX, int posY, int size) {
		this.charImage = charImage;
		this.charSelectedImage = charSelectedImage;
		this.charChosenImage = charChosenImage;
		this.posX = posX;
		this.posY = posY;
		this.size = size;
	}
	
	public void setChosen(boolean chosen) {
		this.chosen = chosen;
	}
	
	public void draw(boolean selected, boolean chosen) {
		// Draw character image.
		charImage.draw(posX, posY, size, size);
		
		if(chosen) {
			// Draw character chosen image.
			charChosenImage.draw(posX, posY, size, size);
		}
		
		if(selected) {
			// Draw character selected image.
			charSelectedImage.draw(posX, posY, size, size);
		}
	}

	@Override
	public void draw(boolean selected, Graphics g, int windowWidth, int windowHeight) {
		// Draw character image.
		charImage.draw(posX, posY, size, size);
		
		if(chosen) {
			// Draw character chosen image.
			charChosenImage.draw(posX, posY, size, size);
		}
		
		if(selected) {
			// Draw character selected image.
			charSelectedImage.draw(posX, posY, size, size);
		}
	}

	@Override
	public int getHeight() {
		return charImage.getHeight();
	}

	@Override
	public int getPosX() {
		return posX;
	}

	@Override
	public int getPosY() {
		return posY;
	}

	@Override
	public int getWidth() {
		return charImage.getWidth();
	}

	@Override
	public void move(int deltaX, int deltaY) {
		setPos(posX + deltaX, posY + deltaY);
	}

	@Override
	public void setPos(int posX, int posY) {
		this.posX = posX;
		this.posY = posY;
	}
}
